<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="eBrain.beans.Item"%>
<%@page import="eBrain.beans.Bid"%>
<jsp:useBean id="dataManager" scope="application"
  class="eBrain.model.DataManager"/>
<% String base = (String)application.getAttribute("base"); %>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Browse Catalog</title>
  <link rel="stylesheet" href="/eBrain/css/eshop.css" type="text/css"/>
  </head>
<body>
<jsp:include page="TopMenu.jsp" flush="true"/>
<jsp:include page="LeftMenu.jsp" flush="true"/>
<div class="content">
<% 		String categoryId = request.getParameter("id");
        ArrayList items = dataManager.getItemsByCategory(categoryId);
        Iterator iterator = items.iterator();
        if(!items.isEmpty()){%>
      
      <table>
        <tr>
          <th>Name</th>
          <th>Start Date</th>
          <th>End Date</th>
          <th>Bid</th>
          </tr>
 <%while (iterator.hasNext()) {
          Item item = (Item)iterator.next();
          
  %>
          <tr>
            <td><a href="<%=base%>?action=openItem&id=<%=item.getId()%>"><%=item.getName()%></a></td>
            <td><%=item.getStart()%></td>
            <td><%=item.getEnd()%></td>
            <td><% Bid bid = dataManager.getMaxBidForItem(item.getId());
            		if(bid.isEmpty()){
            		out.println(item.getStartBid());
            		}
            		else{
            		out.println(bid.getBidValue());
            		}%></td>
            </tr>
<%
          }
          }
          else{
  %>
  		<p>No items in this category  <strong></strong></p>
  
  
  <%} %>
        </table>
      </div>
</body>
</html>
